package com.example.demo.entity;

import com.example.demo.enums.ErrCodeEnum;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

@ApiModel("后台响应报文体的包装")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BackResponseEntity<T> implements Serializable {

    private static final long serialVersionUID = 1L;


    @ApiModelProperty(required = true, value = "响应的Code代码")
    private Integer error_code;

    @ApiModelProperty(required = false, value = "响应的业务数据")
    private T data;

    @ApiModelProperty(required = false, value = "响应的错误消息")
    private String msg;


    public static <T> BackResponseEntity<T> success(ErrCodeEnum errCodeEnum,
                                                                                   T date,
                                                                                   String msg) {
        BackResponseEntity<T> entity =
                new BackResponseEntity<T>();
        entity.setError_code(errCodeEnum.getCode());
        entity.setData(date);
        entity.setMsg(msg);
        return entity;
    }

    public static <T> BackResponseEntity<T> success(ErrCodeEnum errCodeEnum,
                                                                                   String msg) {
        BackResponseEntity<T> entity =
                new BackResponseEntity<T>();
        entity.setError_code(errCodeEnum.getCode());
        entity.setMsg(msg);
        return entity;
    }

    public static <T> BackResponseEntity<T> success(ErrCodeEnum errCodeEnum) {
        BackResponseEntity<T> entity =
                new BackResponseEntity<T>();
        entity.setError_code(errCodeEnum.getCode());
        return entity;
    }


    public Integer getError_code() {
        return error_code;
    }

    public void setError_code(Integer error_code) {
        this.error_code = error_code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
